package com.ruoyi.xiaoshou.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xiaoshou.domain.SalesAudit;
import com.ruoyi.xiaoshou.service.ISalesAuditService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售审核记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/system/audits")
public class SalesAuditController extends BaseController
{
    private String prefix = "system/audit";

    @Autowired
    private ISalesAuditService salesAuditService;

    @RequiresPermissions("system:audit:view")
    @GetMapping()
    public String audit()
    {
        return prefix + "/audit";
    }

    /**
     * 查询销售审核记录列表
     */
    @RequiresPermissions("system:audit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SalesAudit salesAudit)
    {
        startPage();
        List<SalesAudit> list = salesAuditService.selectSalesAuditList(salesAudit);
        return getDataTable(list);
    }

    /**
     * 导出销售审核记录列表
     */
    @RequiresPermissions("system:audit:export")
    @Log(title = "销售审核记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SalesAudit salesAudit)
    {
        List<SalesAudit> list = salesAuditService.selectSalesAuditList(salesAudit);
        ExcelUtil<SalesAudit> util = new ExcelUtil<SalesAudit>(SalesAudit.class);
        return util.exportExcel(list, "销售审核记录数据");
    }

    /**
     * 新增销售审核记录
     */
    @RequiresPermissions("system:audit:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售审核记录
     */
    @RequiresPermissions("system:audit:add")
    @Log(title = "销售审核记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SalesAudit salesAudit)
    {
        return toAjax(salesAuditService.insertSalesAudit(salesAudit));
    }

    /**
     * 修改销售审核记录
     */
    @RequiresPermissions("system:audit:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SalesAudit salesAudit = salesAuditService.selectSalesAuditById(id);
        mmap.put("salesAudit", salesAudit);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售审核记录
     */
    @RequiresPermissions("system:audit:edit")
    @Log(title = "销售审核记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SalesAudit salesAudit)
    {
        return toAjax(salesAuditService.updateSalesAudit(salesAudit));
    }

    /**
     * 删除销售审核记录
     */
    @RequiresPermissions("system:audit:remove")
    @Log(title = "销售审核记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(salesAuditService.deleteSalesAuditByIds(ids));
    }
}
